{extend name="app/admin/view/base.html"/}
{block name="resources"}
{/block}
{block name="main"}
<div class="layui-collapse ns-tips">
	<div class="layui-colla-item">
		<h2 class="layui-colla-title">操作提示</h2>
		<ul class="layui-colla-content layui-show">
			<li>PC端友情链接设置</li>
		</ul>
	</div>
</div>
<div class="layui-form ns-form">
	<input type="hidden" name="id" value="{$id}">
	<div class="layui-form-item">
		<label class="layui-form-label"><span class="required">*</span>链接名称：</label>
		<div class="layui-input-block">
			<input name="link_title" value="{$link_info['link_title']}" type="text" lay-verify="required" class="layui-input ns-len-mid" >
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label"><span class="required">*</span>链接地址：</label>
		<div class="layui-input-block">
			<input name="link_url" value="{$link_info['link_url']}" type="text" lay-verify="required" class="layui-input ns-len-mid" >
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">是否显示：</label>
		<div class="layui-input-block">
			<input type="checkbox" name="is_show" value="1" lay-skin="switch" {if condition="$link_info && $link_info.is_show == 1"} checked {/if} />
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">是否新窗口打开：</label>
		<div class="layui-input-block">
			<input type="checkbox" name="is_blank" value="1" lay-skin="switch" {if condition="$link_info && $link_info.is_blank == 1"} checked {/if}  />
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label"><span class="required"></span>排序：</label>
		<div class="layui-input-block">
			<input name="link_sort" type="text" value="{$link_info['link_sort']}" class="layui-input ns-len-short">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">导航图标：</label>
		<div class="layui-input-block">
			<div class="upload-img-block img-upload">
				<div class="upload-img-box {notempty name="$link_info['link_pic']"}hover{/notempty}">
					<div class="ns-upload-default" id="imgUpload">
						{if condition="$link_info.link_pic"}
						<div id="preview_imgUpload" class="preview_img">
							<img layer-src src="{:img($link_info.link_pic)}" class="img_prev"/>
						</div>
						{else/}
						<div class="upload">
							<img src="ADMIN_IMG/upload_img.png"/>
							<p>点击上传</p>
						</div>
						{/if}
					</div>
					<div class="operation">
						<div>
							<i title="图片预览" class="iconfont iconreview js-preview" style="margin-right: 20px;"></i>
							<i title="删除图片" class="layui-icon layui-icon-delete js-delete"></i>
						</div>
						
						<div class="replace_img js-replace">点击替换</div>
					</div>
					<input type="hidden" name="link_pic" value="{$link_info.link_pic}">
				</div>
			</div>
		</div>
	</div>

	<div class="ns-form-row">
		<button class="layui-btn ns-bg-color" lay-submit lay-filter="save">保存</button>
	</div>

</div>
{/block}

{block name="script"}
<script>
	layui.use(['form'], function() {
		var form = layui.form, repeat_flag=false;

		// 普通图片上传
		var logo_upload = new Upload({
			elem: '#imgUpload'
		});

		form.on('submit(save)', function(data) {
			if(!data.field.link_url){
				layer.msg("请输入链接地址");
				return;
			}
			if (repeat_flag) return;
			repeat_flag = true;
			
			//删除图片
			if(!data.field.link_pic) logo_upload.delete();
			
			$.ajax({
				url: ns.url("pc://admin/pc/editLink"),
				data: data.field,
				dataType: 'JSON',
				type: 'POST',
				success: function(res) {
					layer.msg(res.message);
					if (res.code == 0) {
						location.href = ns.url("pc://admin/pc/linklist");
					}
					repeat_flag = false;
				}
			});
		});
	});
</script>
{/block}